package com.janal.model.admin;

import com.janal.model.Basedao.Basedao;
import com.janal.util.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author Lenovo
 */
public class AdminDaoImpl implements AdminDao{
    @Override
    public Admin getLoginAdmin(Connection conn, String adminCode) throws Exception {
        Admin resultAdmin = null;
        ResultSet rs = null;
        PreparedStatement pstm = null;

        if(conn != null){
            String sql = "select * from admin where adminCode = ?";
            Object[] params = {adminCode};
            rs = Basedao.execute(conn,sql,params,rs,pstm);
            if(rs.next()){
                resultAdmin = new Admin();
                resultAdmin.setAdminCode(rs.getString("adminCode"));
                resultAdmin.setAdminPassword(rs.getString("adminPassword"));
            }
            JdbcUtils.close(rs,pstm,null);
        }
        return resultAdmin;
    }
}
